import 'package:flutter/material.dart';
import '../../Tools/ToolsLocalStorage.dart';

class AppColors {
  // 添加主题模式枚举
  static ThemeMode _themeMode = ThemeMode.system;

  static bool get isDarkMode {
    // 根据选择的主题模式判断
    switch (_themeMode) {
      case ThemeMode.dark:
        return true;
      case ThemeMode.light:
        return false;
      default:
        return WidgetsBinding.instance.window.platformBrightness ==
            Brightness.dark;
    }
  }

  // 添加主题切换方法
  static void switchTheme(int index) {
    switch (index) {
      case 0:
        _themeMode = ThemeMode.light;
        break;
      case 1:
        _themeMode = ThemeMode.dark;
        break;
      case 2:
        _themeMode = ThemeMode.system;
        break;
    }
    // 通知所有使用 AppColors 的 widget 进行重建
    // 注意：这里需要使用状态管理来实现真正的主题切换
  }

  // 主色调
  static Color get primary => const Color(0xFF2AB6F7);

  // Tab文字颜色
  static Color get tabLabelColor => primary;
  static Color get tabUnselectedLabelColor => isDarkMode
      ? const Color(0xFF666666) // 暗黑模式下未选中的颜色
      : const Color(0xFFB9C1D9); // 亮色模式下未选中的颜色

  // 背景色
  static Color get backgroundColor =>
      isDarkMode ? const Color(0xFF121212) : Color(0xF5F5F5F5);

  // 页面背景色
  static Color get pageBackgroundColor =>
      isDarkMode ? const Color(0xFF121212) : const Color(0xFFF5F5F5);

  // 主要文字颜色
  static Color get textPrimary => isDarkMode ? Colors.white : Colors.black;

  // 次要文字颜色
  static Color get textSecondary =>
      isDarkMode ? Color(0xFFB9C1D9) : const Color(0xFF999999);

  // 分割线颜色
  static Color get dividerColor =>
      isDarkMode ? const Color(0xFF2C2C2C) : const Color(0xFFEEEEEE);

  // 卡片背景色
  static Color get cardColor =>
      isDarkMode ? const Color(0xFF202029) : Colors.white;

  // 提示性文字颜色
  static Color get hintColor =>
      isDarkMode ? const Color(0xFF999999) : const Color(0xFFCCCCCC);

  // 初始化主题
  static Future<void> initTheme() async {
    String? savedTheme = await LocalStorage.getstr('theme');
    if (savedTheme != null && savedTheme != 'null') {
      switchTheme(int.parse(savedTheme));
    }
  }
}
